﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Entity;
using System.Data.SqlClient;

namespace LotteryVote.Data
{
    public class MemberPackageDataAccess : DataBase
    {
        public void InsertMemberPackage(User user, CommissionGroup group)
        {
            string sql = string.Format(@"INSERT INTO {0} ({1},{2},{3}) VALUES (@{1},@{2},@{3})",
                MemberPackage.TABLENAME, MemberPackage.USERID, MemberPackage.GROUPID, MemberPackage.SPECIEID);
            base.ExecuteNonQuery(sql, new SqlParameter(MemberPackage.USERID, user.UserId),
                new SqlParameter(MemberPackage.GROUPID, group.GroupId),
                new SqlParameter(MemberPackage.SPECIEID, group.SpecieId));
        }
        public void DeleteMemberPackage(User user, LotterySpeciesEnum specie)
        {
            string sql = string.Format(@"DELETE {0} WHERE {1}=@{1} AND {2}=@{2}", MemberPackage.TABLENAME, MemberPackage.USERID, MemberPackage.SPECIEID);
            base.ExecuteNonQuery(sql, new SqlParameter(MemberPackage.USERID, user.UserId),
                new SqlParameter(MemberPackage.SPECIEID, (int)specie));
        }

        public MemberPackage GetMemberPackageBySpecie(User user, int specieId)
        {
            string sql = string.Format(@"SELECT * FROM {0} WHERE {1}=@{1} AND {2}=@{2}", MemberPackage.TABLENAME, MemberPackage.USERID, MemberPackage.SPECIEID);
            return base.ExecuteEntity<MemberPackage>(sql,
                new SqlParameter(MemberPackage.USERID, user.UserId),
                new SqlParameter(MemberPackage.SPECIEID, specieId));
        }
        public IList<MemberPackage> GetPackageByMember(User user)
        {
            string sql = string.Format(@"SELECT * FROM {0} WHERE {1}=@{1}", MemberPackage.TABLENAME, MemberPackage.USERID);
            return base.ExecuteList<MemberPackage>(sql, new SqlParameter(MemberPackage.USERID, user.UserId));
        }
    }
}
